package com.taotao.thrift;

import com.taotao.thrift.generated.Person;
import com.taotao.thrift.generated.PersonService;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransportException;

/**
 * @Description: Thrift客户端
 * @Author: Chris
 * @Date: Created in 2018/9/21 下午11:46
 */
public class ThriftClient {

    public static void main(String[] args) throws TException {
        TFramedTransport transport = new TFramedTransport(new TSocket("localhost", 8899), 600);
        TProtocol protocol = new TCompactProtocol(transport);
        PersonService.Client client = new PersonService.Client(protocol);

        transport.open();
        Person person = client.getPersonByUsername("Chris");
        System.out.println(person.toString());

        System.out.println("--------");

        Person person1 = new Person();
        person1.setUsername("ChrisT");
        person1.setAge(29);
        person1.setMarried(false);

        client.savePerson(person1);

        transport.close();
    }

}
